package com.giscloud.limp.service.impl;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.giscloud.datasource.page.PageInfo;
import com.giscloud.commons.model.Result;
import cn.hutool.core.collection.CollectionUtil;

import java.util.Date;
import java.util.List;
import com.giscloud.limp.entity.PlaintiffExample;
import com.giscloud.limp.entity.dto.PlaintiffDTO;
import com.giscloud.limp.dao.PlaintiffDao;
import com.giscloud.limp.entity.Plaintiff;
import com.giscloud.limp.service.PlaintiffService;
import lombok.extern.log4j.Log4j2;


@Service("plaintiffService")
@Log4j2
public class PlaintiffServiceImpl implements PlaintiffService {
    private final  PlaintiffDao plaintiffDao;

    @Autowired
    public PlaintiffServiceImpl(PlaintiffDao plaintiffDao) {
        this.plaintiffDao = plaintiffDao;
    }
    /**
    *
    * 列表
    */
    @Override
    public PageInfo queryPage(PlaintiffDTO plaintiffDTO) {
        log.debug("#queryPage parameter ={}", JSON.toJSONString(plaintiffDTO));
        PageHelper.startPage(plaintiffDTO.getPage(), plaintiffDTO.getRows());
        PlaintiffExample plaintiffExample = new PlaintiffExample();
        PlaintiffExample.Criteria criteria = plaintiffExample.createCriteria();
        List<Plaintiff> plaintiffs = plaintiffDao.selectByExample(plaintiffExample);
        return PageInfo.of(plaintiffs);
    }


    /**
     * 信息
     */
    @Override
    public Plaintiff getById(Integer plaintiffId){
        log.debug("#getById parameter ={}", plaintiffId);
        return plaintiffDao.selectByPrimaryKey(plaintiffId);
    }

    /**
     * 保存
     */
    @Override

    public Result save(Plaintiff plaintiff){
        log.debug("#save parameter ={}", JSON.toJSONString(plaintiff));
        plaintiff.setStatusCd(1);
        plaintiff.setCreatedDt(new Date());
        if(plaintiffDao.insertSelective(plaintiff) > 0 ){
            return Result.success("保存成功");
        }else{
            return Result.error("保存失败");
        }
    }

    /**
     * 修改
     */
    @Override

    public Result updateById(Plaintiff plaintiff){
         log.debug("#updateById parameter ={}", JSON.toJSONString(plaintiff));
         PlaintiffExample plaintiffExample = new PlaintiffExample();
         PlaintiffExample.Criteria criteria = plaintiffExample.createCriteria();
         criteria.andPlaintiffIdEqualTo(plaintiff.getPlaintiffId());
         if(plaintiffDao.updateByExampleSelective(plaintiff,plaintiffExample) > 0){
             return Result.success("修改成功");
         }else{
             return Result.error("修改失败");
         }
    }
    /**
     * 删除
     */
    @Override

    public Result removeByIds(List<Integer> plaintiffIds){
        log.debug("#removeByIds parameter ={}", JSON.toJSONString(plaintiffIds));
        PlaintiffExample plaintiffExample = new PlaintiffExample();
        PlaintiffExample.Criteria criteria = plaintiffExample.createCriteria();

            criteria.andPlaintiffIdIn(plaintiffIds);

        if(plaintiffDao.deleteByExample(plaintiffExample) > 0){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

}